const {loginCheck} = require("../controller/user.js");
const { SuccessModel, ErrorModel } = require("../model/resModel");

const handleUserRouter = (req, res) => {
  const {method,path} = req;
  const {username, password} = req.body;
  console.log("登录相关信息:",username, password);
  // 获取登录的接口
  if (method == 'POST' && path == '/api/user/login') {
    const resultLogin = loginCheck(username, password);
    return resultLogin.then(userdata => {
      if (userdata.username) {
        return new SuccessModel("登录成功");
      }
      return new ErrorModel("登录失败");
    })
  }
}

module.exports = handleUserRouter;